package com.yanchangapp.adapter;

import android.support.annotation.Nullable;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.yanchangapp.R;
import com.yanchangapp.model.bean.OrderProductBean;
import com.yanchangapp.widget.ExpandLayout;
import com.zxl.baselib.util.formatter.BigDecimalUtils;
import com.zxl.baselib.util.ui.ResHelper;

import java.util.List;

/**
 * Created by apple on 2019-08-08.
 * description:
 */
public class PsDetailProductAdapter extends BaseQuickAdapter<OrderProductBean, BaseViewHolder> {
    public PsDetailProductAdapter(int layoutResId, @Nullable List<OrderProductBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, OrderProductBean productsBean) {
        // 名字
        baseViewHolder.setText(R.id.tvProductName,productsBean.getProductName());
        // 单价 数量 总价
        baseViewHolder.setText(R.id.tvProductPrice,
                ResHelper.getString(R.string.order_product_single_price,
                        BigDecimalUtils.keep2Decimal(productsBean.getPrice())));
        int num;
        if (productsBean.getOrderNum() == 0){
            num = productsBean.getPurNum();
        }else {
            num = productsBean.getOrderNum();
        }
        baseViewHolder.setText(R.id.tvProductNum,
                ResHelper.getString(R.string.order_product_num,String.valueOf(num))
                );
        baseViewHolder.setText(R.id.tvProductTotal,
                ResHelper.getString(R.string.order_product_total_money,BigDecimalUtils.keep2Decimal(productsBean.getMoney())));
        //设置折叠栏目的信息
        baseViewHolder.setText(R.id.tvProductNo,productsBean.getProductNo());
        baseViewHolder.setText(R.id.tvProductFormat,productsBean.getProductFormat());
        baseViewHolder.setText(R.id.tvRegistratNoName,productsBean.getRegistratNoName());
        baseViewHolder.setText(R.id.tvRegistratNo,productsBean.getRegistratNo());
        baseViewHolder.setText(R.id.tvManufacturer,productsBean.getManufacturer());
        ImageView ivArrow = baseViewHolder.getView(R.id.ivArrow);
        ExpandLayout expandLayout = baseViewHolder.getView(R.id.expandLayout);
        if (expandLayout != null) {
            expandLayout.initExpand(false,ivArrow,true);
        }

        RelativeLayout rlHead = baseViewHolder.getView(R.id.rlHead);
        rlHead.setOnClickListener(v -> {
            if (expandLayout != null){
                expandLayout.toggleExpand();
            }
        });

    }
}
